from django import forms
from .models import User, Article
from django.core.validators import RegexValidator
from django.core.exceptions import ValidationError


class UserRegisterForm(forms.ModelForm):
    phone = forms.CharField(max_length=20, min_length=6, widget=forms.widgets.TextInput(
        attrs={"class": "form-control"}))
    password = forms.CharField(max_length=12, widget=forms.widgets.PasswordInput(
        attrs={"class": "form-control"}))

    class Meta:
        model = User
        fields = ['phone', 'password']


class UserLoginForm(forms.Form):
    phone = forms.CharField(max_length=11, min_length=11)
    password = forms.CharField(max_length=12, min_length=6)


class UserIndexForm(forms.ModelForm):
    portrait = forms.ImageField(label="头像", required=False)
    nickname = forms.CharField(max_length=20, min_length=6, label="昵称", widget=forms.widgets.TextInput(
        attrs={"class": "form-control"}))
    phone = forms.CharField(max_length=20, min_length=6, label="手机号", widget=forms.widgets.TextInput(
        attrs={"class": "form-control"}))

    class Meta:
        model = User
        fields = ['phone', 'nickname', 'portrait']


class ArticleForm(forms.ModelForm):
    title = forms.CharField(max_length=50, required=True, label='内容名称')
    sort = forms.CharField(
        widget=forms.RadioSelect(choices=(('新闻', '新闻'), ('政策', '政策'), ('行情', '行情'), ('技术', '技术'))),
        required=True,
        label='类型')
    source = forms.CharField(max_length=50, required=True, label='来源')
    abstract = forms.CharField(max_length=50, required=True, label='摘要')
    images = forms.ImageField(required=True, label='内容封面')
    content = forms.CharField(max_length=50, required=True, label='内容')

    class Meta:
        model = Article
        fields = ['title', 'sort', 'source', 'abstract', 'images',
                  'content']





# from django import forms
# from .models import LoginUser
# from django.core.validators import RegexValidator
# from django.core.exceptions import ValidationError
#
#
# class UserRegisterForm(forms.ModelForm):
#     phone = forms.CharField(max_length=20, min_length=6, widget=forms.widgets.TextInput(
#         attrs={"class": "form-control"}))
#     password = forms.CharField(max_length=12, widget=forms.widgets.PasswordInput(
#         attrs={"class": "form-control"}))
#     password1 = forms.CharField(max_length=12, widget=forms.widgets.PasswordInput(
#         attrs={"class": "form-control"}))
#
#     class Meta:
#         model = LoginUser
#         fields = ['phone', 'password']
#
#
# class UserLoginForm(forms.Form):
#     phone = forms.CharField(max_length=11, min_length=11)
#     password = forms.CharField(max_length=12, min_length=6)
